package io.chain.ko.service.impl;

import java.util.List;

import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.mapper.EntityWrapper;

import io.chain.ko.entity.TUser;
import io.chain.ko.mapper.UserMapper;
import io.chain.ko.service.UserService;

@Service
@Transactional(readOnly=true)
public class UserServiceImpl implements UserService {
	
	@Autowired
	private UserMapper userMapper;

	@Override
	public TUser findByUsername(String username) {
		TUser tuser=new TUser();
		tuser.setUsername(username);		
		return userMapper.selectOne(tuser);
	}

	@Override
	@Transactional(readOnly=false,rollbackFor=Exception.class)
	public Integer saveUser(TUser tuser) {
		return userMapper.insertAllColumn(tuser);
	}

	@Override
	@Transactional(readOnly=false,rollbackFor=Exception.class)
	public Integer updateUser(TUser tuser) {
		return userMapper.updateAllColumnById(tuser);
	}

	@Override
	public List<TUser> findUser(int pageSize, int page,TUser tuser) {
		int limit=pageSize;
		int offset=(page-1)*pageSize;
		RowBounds rowBounds=new RowBounds(offset,limit);
		EntityWrapper<TUser> wrapper=new EntityWrapper<TUser>(tuser);
		return userMapper.selectPage(rowBounds, wrapper);
	}

}
